package com.fxp.project.jiuselu.web.business.v1.controller.payimage;

import java.util.List;

import com.fxp.project.jiuselu.web.base.controller.BaseController;
import com.fxp.project.jiuselu.web.domain.CommonResult;
import com.fxp.project.jiuselu.web.models.payimage.entity.PayImg;
import com.fxp.project.jiuselu.web.models.payimage.mapper.PayImgMapper;
import com.fxp.project.jiuselu.web.models.payimage.service.IPayImgService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单付款凭证Controller
 *
 * @author Jason.Wang
 * @date 2022-05-23
 */
@RestController
@RequestMapping("/system/img")
public class PayImgController extends BaseController
{
    @Autowired
    private IPayImgService payImgService;

    @Autowired
    private PayImgMapper payImgMapper;

//    /**
//     * 查询订单付款凭证列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:img:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(PayImg payImg)
//    {
//        startPage();
//        List<PayImg> list = payImgService.selectPayImgList(payImg);
//        return getDataTable(list);
//    }
//
//    /**
//     * 导出订单付款凭证列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:img:export')")
//    @Log(title = "订单付款凭证", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(PayImg payImg)
//    {
//        List<PayImg> list = payImgService.selectPayImgList(payImg);
//        ExcelUtil<PayImg> util = new ExcelUtil<PayImg>(PayImg.class);
//        return util.exportExcel(list, "订单付款凭证数据");
//    }
//
//    /**
//     * 获取订单付款凭证详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('system:img:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return AjaxResult.success(payImgService.selectPayImgById(id));
//    }


    /**
     * 获取订单是否上传付款凭证
     */
    @PostMapping("/getPayType")
    @CrossOrigin
    public CommonResult getPayType(@RequestBody PayImg payImg)
    {
        PayImg payImg1 = payImgMapper.selectPayImgOrder(payImg.getOrderId());
        if(payImg1!=null){
            return CommonResult.success(payImg1);
        }
        return CommonResult.success("未上传凭证");
    }
    /**
     * 新增订单付款凭证
     */
    @PostMapping("insertPayImg")
    @CrossOrigin
    public CommonResult add(@RequestBody PayImg payImg)
    {
        PayImg payImg1 = payImgMapper.selectPayImgOrder(payImg.getOrderId());
        if(payImg1!=null){
            return CommonResult.failed("不可重复上传");
        }
        return CommonResult.success(payImgService.insertPayImg(payImg));
    }

//    /**
//     * 修改订单付款凭证
//     */
//    @PreAuthorize("@ss.hasPermi('system:img:edit')")
//    @Log(title = "订单付款凭证", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody PayImg payImg)
//    {
//        return toAjax(payImgService.updatePayImg(payImg));
//    }
//
//    /**
//     * 删除订单付款凭证
//     */
//    @PreAuthorize("@ss.hasPermi('system:img:remove')")
//    @Log(title = "订单付款凭证", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(payImgService.deletePayImgByIds(ids));
//    }
}
